package com.ruoyi.game.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.game.domain.entity.GameConfig;
import com.ruoyi.game.service.IGameConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游戏配置Controller
 * 
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/app/game/config")
public class GameConfigController extends BaseController
{
    @Autowired
    private IGameConfigService gameConfigService;

    /**
     * 查询游戏配置列表
     */
    @PreAuthorize("@ss.hasPermi('game:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameConfig gameConfig)
    {
        startPage();
        List<GameConfig> list = gameConfigService.selectGameConfigList(gameConfig);
        return getDataTable(list);
    }

    /**
     * 导出游戏配置列表
     */
    @PreAuthorize("@ss.hasPermi('game:config:export')")
    @Log(title = "游戏配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameConfig gameConfig)
    {
        List<GameConfig> list = gameConfigService.selectGameConfigList(gameConfig);
        ExcelUtil<GameConfig> util = new ExcelUtil<GameConfig>(GameConfig.class);
        util.exportExcel(response, list, "游戏配置数据");
    }

    /**
     * 获取游戏配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gameConfigService.selectGameConfigById(id));
    }

    /**
     * 新增游戏配置
     */
    @PreAuthorize("@ss.hasPermi('game:config:add')")
    @Log(title = "游戏配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameConfig gameConfig)
    {
        return toAjax(gameConfigService.insertGameConfig(gameConfig));
    }

    /**
     * 修改游戏配置
     */
    @PreAuthorize("@ss.hasPermi('game:config:edit')")
    @Log(title = "游戏配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameConfig gameConfig)
    {
        return toAjax(gameConfigService.updateGameConfig(gameConfig));
    }

    /**
     * 删除游戏配置
     */
    @PreAuthorize("@ss.hasPermi('game:config:remove')")
    @Log(title = "游戏配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gameConfigService.deleteGameConfigByIds(ids));
    }
}
